﻿<%@ Page Title="Quản lý chuyên gia" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="New.aspx.cs" Inherits="Dost.Khcn.Web.ChuyenGia.New" %>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%=Resources.GlobalStrings.AddNew %> chuyên gia</h2>
    <p></p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></span>
    <div>
        <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
            <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Thông tin chung</a></li>
            </ul>
            <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <table>
                    <tr>
                        <td colspan="5">
                            <h3>Thông tin chung</h3>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Họ tên:</td>
                        <td>
                            <input id="HoTen" data-bind="value: ChuyenGia().HoTen" class="validate[required] name" /></td>
                        <td style="width: 10px;"></td>
                        <td style="text-align: right;">Giới tính:</td>
                        <td>
                            <input type="radio" name="GioiTinh" data-bind="checked: ChuyenGia().GioiTinh, checkedValue: true" />
                            Nam
                            <input type="radio" name="GioiTinh" data-bind="checked: ChuyenGia().GioiTinh, checkedValue: false" />
                            Nữ</td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Năm sinh:</td>
                        <td>
                            <input id="NamSinh" data-bind="value: ChuyenGia().NamSinh" class="validate[custom[onlyNumberSp]] date" /></td>
                        <td></td>
                        <td style="text-align: right;">Dân tộc:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().DanToc" class="date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Địa chỉ liên hệ:</td>
                        <td colspan="4">
                            <input data-bind="value: ChuyenGia().DiaChi" class="longname" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Điện thoại:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().DienThoai" class="name" /></td>
                        <td></td>
                        <td style="text-align: right;">Email:</td>
                        <td>
                            <input id="Email" data-bind="value: ChuyenGia().Email" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Học hàm:</td>
                        <td>
                            <select data-bind="options: $root.HocHams, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HocHamId"></select></td>
                        <td></td>
                        <td style="text-align: right;">Năm được phong học hàm:</td>
                        <td>
                            <input id="NamHocHam" data-bind="value: ChuyenGia().NamHocHam" class="validate[custom[onlyNumberSp]] date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Học vị:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.HocVis, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HocViId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Chức vụ:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().ChucVu" class="name" /></td>
                        <td></td>
                        <td style="text-align: right;">Chức danh nghiên cứu:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().ChucDanh" class="name" /></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;">Đơn vị đang công tác (hoặc trước khi nghỉ hưu):</td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Tên đơn vị:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().TenDonVi" class="name" /></td>
                        <td style="width: 10px;"></td>
                        <td style="text-align: right;">Điện thoại:</td>
                        <td>
                            <input data-bind="value: ChuyenGia().DienThoaiDonVi" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Địa chỉ:</td>
                        <td colspan="4">
                            <input data-bind="value: ChuyenGia().DiaChiDonVi" class="longname" /></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;"></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Lĩnh vực nghiên cứu:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.NhomLinhVucs, optionsText: 'MaTen', optionsValue: 'Id', value: selectedNhomLinhVuc"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Ngành nghiên cứu:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.LinhVucs, optionsText: 'MaTen', optionsValue: 'Id', value: ChuyenGia().LinhVucId"></select></td>
                    </tr>
                    <tr>
                        <td colspan="5">
                            <h3>Quá trình đào tạo</h3>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Chuyên ngành đào tạo:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.ChuyenNganhs, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().ChuyenNganhId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Hình thức đào tạo:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.HinhThucDaoTaos, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HinhThucDaoTaoId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Cơ sở đào tạo:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.CoSoDaoTaos, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().CoSoDaoTaoId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Nước cấp:</td>
                        <td>
                            <select data-bind="options: $root.QuocGias, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().QuocGiaId"></select></td>
                        <td></td>
                        <td style="text-align: right;">Năm nhận học vị:</td>
                        <td>
                            <input id="NamHocVi" data-bind="value: ChuyenGia().NamHocVi" class="validate[custom[onlyNumberSp]] date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Tên luận án:</td>
                        <td colspan="4">
                            <textarea data-bind="value: ChuyenGia().TenLuanAn" class="longname"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;"></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Trình độ ngoại ngữ:</td>
                        <td colspan="4">
                            <input data-bind="value: ChuyenGia().NgoaiNgu" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Thành tựu hoạt động<br />
                            KH&CN khác:</td>
                        <td colspan="4">
                            <textarea data-bind="value: ChuyenGia().ThanhTuuKhcnKhac" class="longname"></textarea></td>
                    </tr>
                    <%--<tr>
                        <td colspan="5">Đồng ý công khai thông tin (trên website của Sở KH&CN Khánh Hòa):</td>
                    </tr>--%>
                    <%--<tr>
                        <td style="text-align: right;"></td>
                        <td colspan="4"><input type="checkbox" data-bind="checked: ChuyenGia().CongKhai, checkedValue: true" /> Đồng ý</td>
                    </tr>--%>
                    <tr>
                        <td style="text-align: right;"></td>
                        <td>
                            <p>
                                <button class="submitButton" data-bind="click: save"><%=Resources.GlobalStrings.Save %></button>
                            </p>
                        </td>
                        <td></td>
                        <td style="text-align: right;"></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;"></td>
                        <td></td>
                        <td></td>
                        <td style="text-align: right;"></td>
                        <td></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <div>
        <p>
            <input id="btnCancel" type="button" value="<%=Resources.GlobalStrings.Cancel %>"
                class="submitButton" onclick="javascript: window.location = 'List.aspx';" />
        </p>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#tabs").tabs();
            $("#Form1").validationEngine();
        });
    </script>

    <script type="text/javascript">
        var ChuyenGiaModel = {
            HoTen: ko.observable(""),
            NamSinh: ko.observable(),
            HocHamId: ko.observable(),
            Email: ko.observable(),
            GioiTinh: ko.observable(true),
            DanToc: ko.observable('Kinh'),
            DiaChi: ko.observable(),
            DienThoai: ko.observable(),
            NamHocHam: ko.observable(),
            HocViId: ko.observable(),
            ChucVu: ko.observable(),
            ChucDanh: ko.observable(),
            TenDonVi: ko.observable(),
            DiaChiDonVi: ko.observable(),
            DienThoaiDonVi: ko.observable(),
            LinhVucId: ko.observable(),
            NgoaiNgu: ko.observable(),
            ChuyenNganhId: ko.observable(),
            HinhThucDaoTaoId: ko.observable(),
            CoSoDaoTaoId: ko.observable(),
            QuocGiaId: ko.observable(),
            NamHocVi: ko.observable(),
            TenLuanAn: ko.observable(),
            ThanhTuuKhcnKhac: ko.observable(),
            CongKhai: ko.observable(true)
        };

        function ChuyenGiaViewModel() {
            var self = this;
            // data
            self.ChuyenGia = ko.observable(ChuyenGiaModel);
            self.HocHams = ko.observableArray();
            self.HocVis = ko.observableArray();
            self.LinhVucs = ko.observableArray();
            self.ChuyenNganhs = ko.observableArray();
            self.HinhThucDaoTaos = ko.observableArray();
            self.CoSoDaoTaos = ko.observableArray();
            self.QuocGias = ko.observableArray();
            self.NhomLinhVucs = ko.observableArray();
            self.selectedNhomLinhVuc = ko.observable();
            self.AllLinhVucs = {};

            // hoc ham
            $.ajax({
                url: "/DanhMuc/HocHam/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.HocHams(data.d);
                }
            });
            // hoc vi
            $.ajax({
                url: "/DanhMuc/HocVi/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.HocVis(data.d);
                }
            });
            // nhomlinh vuc
            $.ajax({
                url: "/DanhMuc/LinhVuc/NhomLinhVuc.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.NhomLinhVucs(data.d);
                }
            });
            // linh vuc
            $.ajax({
                url: "/DanhMuc/LinhVuc/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.AllLinhVucs = data.d;
                    self.LinhVucs(data.d);
                }
            });
            // chuyen nganh
            $.ajax({
                url: "/DanhMuc/ChuyenNganh/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.ChuyenNganhs(data.d);
                }
            });
            // hinh thuc dao tao
            $.ajax({
                url: "/DanhMuc/HinhThucDaoTao/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.HinhThucDaoTaos(data.d);
                }
            });
            // co so dao tao
            $.ajax({
                url: "/DanhMuc/CoSoDaoTao/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.CoSoDaoTaos(data.d);
                }
            });
            // quoc gia
            $.ajax({
                url: "/DanhMuc/QuocGia/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    self.QuocGias(data.d);
                }
            });

            // behaviors
            self.selectedNhomLinhVuc.subscribe(function () {
                if (self.selectedNhomLinhVuc() === 0) {
                    self.LinhVucs(self.AllLinhVucs);
                } else {
                    var linhVucs = new Array();
                    $.each(self.AllLinhVucs, function (index, linhVuc) {
                        if (linhVuc.Id === 0) {
                            linhVucs.push(linhVuc);
                        }
                        else if (linhVuc.NhomLinhVucId === self.selectedNhomLinhVuc()) {
                            linhVucs.push(linhVuc);
                        }
                    });
                    self.LinhVucs(linhVucs);
                }
            });

            self.save = function () {
                var valid = $("#Form1").validationEngine('validate');
                if (!valid) return false;

                $.blockUI();
                $.ajax({
                    url: "New.aspx/Create",
                    data: JSON.stringify({ chuyenGia: ko.toJS(self.ChuyenGia()) }),
                    type: "post",
                    contentType: "application/json",
                    dataType: "json",
                    async: true,
                    success: function (result) {
                        if (result.d.Result == "OK") {
                            window.location = "Edit.aspx?id=" + result.d.Data.Id;
                        } else {
                            alert(result.d.Message);
                        }
                    }
                });
                return false;
            };
        }

        var chuyenGiaViewModel = new ChuyenGiaViewModel();

        ko.applyBindings(chuyenGiaViewModel);
    </script>
</asp:Content>
